<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 
 
 
class Administracion extends CI_Controller {
 
    /**
     * Index Page for this controller.
     *
     * Maps to the following URL
     *      http://example.com/index.php/welcome
     *  - or -  
     *      http://example.com/index.php/welcome/index
     *  - or -
     * Since this controller is set as the default controller in 
     * config/routes.php, it's displayed at http://example.com/
     *
     * So any other public methods not prefixed with an underscore will
     * map to /index.php/welcome/<method_name>
     * @see http://codeigniter.com/user_guide/general/urls.html
     */
      
     var $ruta;
     var $title;
     var $modelo;
     var $modeloSingular;
     var $idModelo;
      
     public function __construct() {
        parent::__construct();
        $this->load->library('session');
        $usuario=$this->session->userdata('usuario');
        //echo $usuario['perfil'];exit();
            if($usuario['id']>0 || $usuario['usuario']!=''){
            //echo 'Soy usuario logueado';
            }else{
            	//me deslogueo
            header('Location:'.base_url().'login/logout');
            } 
    }
     
    private function inicializar($modo,$data1,$data2,$data3=NULL,$data4=NULL){
        $this->ruta='administracion/';
        $this->title='NUNA Psicologos | Admin';
        $content['CXTitle']=$this->title;
        $content['CXRuta']=$this->ruta;
        $content['CXModo']=$modo;
        $content['CXData1']=$data1;
        $content['CXData2']=$data2;
		$content['CXData3']=$data3;
        $content['CXData4']=$data4;
        return $content;    
        }
      
    public function index($page='usuario',$mode=NULL)
    {
        $this->load->library('session');
        $usuario=$this->session->userdata('usuario');
        //Por defecto cargara el administrador de usuario
		$this->usuario($mode);
            
    }
     
     
    private function action($content){
        $Constructor=NULL;
         
        $content['CXRuta']=$this->ruta.strtolower($content['CXModeloSingular']);
        
        
        $content['CXIdModelo']='id'.$content['CXModeloSingular'];
        $p=strtolower($content['CXModeloSingular']);
         
        #############
        $id='';
        $id2='';
        $tipo='';
        $action='';
        #############
         
        if($content['CXModo']=='view' || $content['CXModo']=='edit' || $content['CXModo']=='cortarmediano' || $content['CXModo']=='cortarchico' || $content['CXModo']=='delete' || $content['CXModo']=='pagar' || $content['CXModo']=='estadocuenta' || $content['CXModo']=='lotes' || $content['CXModo']=='download1' || $content['CXModo']=='download2'  || $content['CXModo']=='change' || $content['CXModo']=='printpdf' || $content['CXModo']=='estado'){
            $id=$content['CXData1'];$action=$content['CXData2'];
             
            }elseif($content['CXModo']=='add'){
                $action=$content['CXData1'];
            }elseif($content['CXModo']=='table2'){
                $tipo=$content['CXData1'];$id=$content['CXData2'];
                 
                }elseif($content['CXModo']=='add2'){
                    $action=$content['CXData1'];$tipo=$content['CXData2'];$id=$content['CXData3'];
                    }elseif($content['CXModo']=='edit2'){
                    $action=$content['CXData1'];$tipo=$content['CXData2'];$id=$content['CXData3'];$id2=$content['CXData4'];
                    }elseif($content['CXModo']=='add3'){
                    $action=$content['CXData1'];$id=$content['CXData2'];
                    }elseif($content['CXModo']=='edit3' || $content['CXModo']=='view3'){
                    $action=$content['CXData1'];$id=$content['CXData2'];$id2=$content['CXData3'];
                    }
                    //var_dump($content);
        $this->load->library('construct'.strtolower($content['CXModeloSingular']));
         
        switch($p){
            case 'usuario'  :   $Constructor=$this->constructusuario; break;
             
        }
         
         
        switch($content['CXModo']){
            case 'view': 
                if($action=='submit') $Constructor->submit($content,$id); else $Constructor->form($content,"Ver",$id);
                break;
            case 'edit': 
                if($action=='submit') $Constructor->submit($content,$id); else $Constructor->form($content,"Editar",$id);
                break; 
            case 'estado': 
                if($action=='submit') $Constructor->submit($content,$id); else $Constructor->formEstado($content,"Estado",$id); 
                break;
            case 'change': 
                if($action=='submit') $Constructor->submit($content,$id); else $Constructor->form($content,"Change",$id);
                break;
            case 'add': 
                if($action=='submit') $Constructor->submit($content); else $Constructor->form($content,"Agregar",0);
                break;
            case 'add2': 
                if($action=='submit') $Constructor->submit($content,$id); else $Constructor->form($content,"Agregar",$id,$tipo);
                break;
            case 'edit2': 
                if($action=='submit') $Constructor->submit($content,$id); else $Constructor->form($content,"Editar",$id,$tipo,$id2);
                break;
            case 'add3': 
                if($action=='submit') $Constructor->submit($content,$id); else $Constructor->form($content,"Agregar",$id);
                break;
            case 'edit3': 
                if($action=='submit') $Constructor->submit($content,$id); else $Constructor->form($content,"Editar",$id,$id2);
                break;
            case 'view3': 
                if($action=='submit') $Constructor->submit($content,$id); else $Constructor->form($content,"Ver",$id,$id2);
                break;
            case 'pagar': 
                if($action=='submit') $Constructor->submit($content,$id); else $Constructor->formPagar($content,"Pagar",$id);
                break;
            case 'estadocuenta': 
                $Constructor->viewEstadoCuenta($content,$id);
                break;
            case 'download1': 
                $Constructor->download1();
                break;
            case 'download2': 
                $Constructor->download2();
                break;
            case 'download': 
                $Constructor->download($content);
                break;
            case 'lotes': 
                $Constructor->viewLote($content,$id);
                break;
            case 'table2': 
                $Constructor->viewTable($content,$tipo,$id);
                break;
            case 'delete':
                if($action=='submit') $Constructor->submit($content,$id);
            break;
            case 'print':
                 $this->formPrint($id);
            break;
            case 'printpdf':
                 $Constructor->printpdf();
            break;
            case 'cortarmediano': 
                if($action=='submit') $Constructor->submit($content,$id); else $Constructor->cortarmediano($content,"Editar",$id);
                break;
            case 'cortarchico': 
                if($action=='submit') $Constructor->submit($content,$id); else $Constructor->cortarchico($content,"Editar",$id);
                break;
             
            default: $Constructor->viewTable($content);
            }
        $this->load->library('service');
        //$this->service->generarAuditoria($p,$content['CXModo'],$id,$id2,$tipo,$action);
        
        }
     
    public function usuario($modo=NULL,$data1=NULL,$data2=NULL){
        $content=$this->inicializar($modo,$data1,$data2);
        $content['CXModelo']='Usuarios';
        $content['CXModeloSingular']=trim($content['CXModelo'],'s');
        $this->action($content);
    }
     
    public function imagen($modo=NULL,$data1=NULL,$data2=NULL,$data3=NULL,$data4=NULL){
        $content=$this->inicializar($modo,$data1,$data2);
        $content['CXModelo']='Imagenes';
        $content['CXModeloSingular']='Imagen';
        $content['CXData3']=$data3;
        $content['CXData4']=$data4;
        $this->action($content);
    }
     
     
}
 
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */